Previous | Home | Next |
An array is the collection of similar type of objects. Array in VB.net is different for the array of C++ and other languages because they are objects. This provides them useful methods and property. Arrays allow a group of elements of a particular type to be stored in a contiguous block of memory. Array types derive from System.Array and are declared in VB.net using brackets (()).
Syntax
datatype [ ] array-name;
Example
Dim books As Integer()()() = New Integer(2)()() {};
Multidimensional Array
Multidimensional Arrays of two types Rectangular Array and Jagged Array Rectangular Array represents n-dimensional blocks.
Example
Dim age As Integer(,,) = New Integer(16, 19, 33) {}
Jagged Arrays are arrays of arrays.
Dim books As Integer()()() = New Integer(2)()() {} For i As Integer = 0 To 2 books(i) = New Integer(3)() {} For j As Integer = 0 To 3 books(i)(j) = New Integer(4) {} Next Next
Indexer
Indexers are usually known as smart array in VB.net.It is used for treating object as an array.Defining an indexer in VB.net is much like same as defining properties. Or we can say that an indexer is a member that enables an object to be indexed in the same way as an array.
Collections
Collections are the enumerable data structure in VB.net that can be assessed using indexes or keys. Types of collections in VB.net are given below-
System.Collections namespace
This provides a lot of classes, methods and properties to interact with the varying data structures that are supported by it. The interfaces that are defined in this namespace include
- IEnumerable
- IEnumerator
- ICollection
- IList
- IDictionary
System.Collections.Stack
System.Collections.Queue Both are derived from ICollection Interface.
- The collections that inherit the IDictionary interface include: System.Collections.SortedList
- System.Collections.Hashtable
The IList interface represents collections that only have value. The following are the classes that extend this interface:
- System.Array
- System.Collections.ArrayList
- System.Collections.Specialized.StringCollection
Concrete Collection Classes
ArrayList class: This works by maintaining an internal array of objects that is replaced with a larger array when it reaches its capacity of elements.
BitArray class: It is a dynamically sized array of Boolean values. It is more memory-efficient than a simple array of bools because it uses only one bit for each value.
Hashtable class : A Hashtable is a standard dictionary (key/value) data structure that uses a hashing algorithm to store and index values efficiently.
Queue class : A Queue is a standard first-in, first-out (FIFO) data structure, providing simple operations to enqueue, dequeue, peek, etc.
SortedList class :A SortedList is a standard dictionary data structure that uses a binary-chop search to index efficiently.
Stack class : A Stack is a standard last-in first-out (LIFO) data structure.
StringCollection class: A StringCollection is a standard collection data structure for storing strings.
Previous | Home | Next |